home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / minion.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  5.9 KB  |  268 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)minion.c    3.1    92/11/01    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6. #include "emin.h"
  7. #include "epri.h"
  8.  
  9. void
  10. msummon(ptr)        /* ptr summons a monster */
  11. register struct permonst *ptr;
  12. {
  13.     register int dtype = 0, cnt = 0, atyp = sgn(ptr->maligntyp);
  14.  
  15.     if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) {
  16.  
  17.         dtype = (!rn2(20)) ? dprince(atyp) :
  18.                  (!rn2(4)) ? dlord(atyp) : ndemon(atyp);
  19.         cnt = (!rn2(4) && !is_dprince(&mons[dtype])) ? 2 : 1;
  20.  
  21.     } else if (is_dlord(ptr)) {
  22.  
  23.         dtype = (!rn2(50)) ? dprince(atyp) :
  24.                  (!rn2(20)) ? dlord(atyp) : ndemon(atyp);
  25.         cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
  26.  
  27.     } else if (is_ndemon(ptr)) {
  28.  
  29.         dtype = (!rn2(20)) ? dlord(atyp) :
  30.                  (!rn2(6)) ? ndemon(atyp) : monsndx(ptr);
  31.         cnt = 1;
  32.     } else if (is_lminion(ptr)) {
  33.  
  34.         dtype = (is_lord(ptr) && !rn2(20)) ? llord() :
  35.              (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr);
  36.         cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
  37.  
  38.     }
  39.  
  40.     if (!dtype) return;
  41.  
  42.     /*
  43.      * If this daemon is unique and being re-summoned (the only way we
  44.      * could get this far with an extinct dtype), try another.
  45.      */
  46.     if (mons[dtype].geno & (G_EXTINCT | G_GENOD)) {
  47.         dtype = ndemon(atyp);
  48.         if (!dtype) return;
  49.     }
  50.  
  51.     while (cnt > 0) {
  52.  
  53.         (void)makemon(&mons[dtype], u.ux, u.uy);
  54.         cnt--;
  55.     }
  56.     return;
  57. }
  58.  
  59. void
  60. summon_minion(alignment, talk)
  61. aligntyp alignment;
  62. boolean talk;
  63. {
  64.     register struct monst *mon;
  65.     int mnum;
  66.  
  67.     switch ((int)alignment) {
  68.     case A_LAWFUL:
  69.         mnum = lminion();
  70.         break;
  71.     case A_NEUTRAL:
  72.         mnum = PM_AIR_ELEMENTAL + rn2(4);
  73.         break;
  74.     case A_CHAOTIC:
  75.     case A_NONE:
  76.         mnum = ndemon(alignment);
  77.         break;
  78.     default:
  79.         impossible("unaligned player?");
  80.         mnum = ndemon(A_NONE);
  81.         break;
  82.     }
  83.     if (mons[mnum].pxlth == 0) {
  84.     struct permonst *pm = &mons[mnum];
  85.     pm->pxlth = sizeof(struct emin);
  86.     mon = makemon(pm, u.ux, u.uy);
  87.     pm->pxlth = 0;
  88.     if (mon) {
  89.         mon->isminion = TRUE;
  90.         EMIN(mon)->min_align = alignment;
  91.     }
  92.     } else if (mnum == PM_ANGEL) {
  93.     mon = makemon(&mons[mnum], u.ux, u.uy);
  94.     if (mon) {
  95.         mon->isminion = TRUE;
  96.         EPRI(mon)->shralign = alignment;    /* always A_LAWFUL here */
  97.     }
  98.     } else
  99.     mon = makemon(&mons[mnum], u.ux, u.uy);
  100.     if (mon) {
  101.     if (talk) {
  102.         pline("The voice of %s booms:", align_gname(alignment));
  103.         verbalize("Thou shalt pay for thy indiscretion!");
  104.         if (!Blind)
  105.         pline("%s appears before you.", Amonnam(mon));
  106.     }
  107.     mon->mpeaceful = FALSE;
  108.     /* don't call set_malign(); player was naughty */
  109.     }
  110. }
  111.  
  112. #define    Athome    (Inhell && !mtmp->cham)
  113.  
  114. int
  115. demon_talk(mtmp)        /* returns 1 if it won't attack. */
  116. register struct monst *mtmp;
  117. {
  118.     long    demand, offer;
  119.  
  120.     if (uwep && uwep->oartifact == ART_EXCALIBUR) {
  121.         pline("%s looks very angry.", Amonnam(mtmp));
  122.         mtmp->mpeaceful = mtmp->mtame = 0;
  123.         newsym(mtmp->mx, mtmp->my);
  124.         return 0;
  125.     }
  126.  
  127.     /* Slight advantage given. */
  128.     if (is_dprince(mtmp->data) && mtmp->minvis) {
  129.         mtmp->minvis = 0;
  130.         if (!Blind) pline("%s appears before you.", Amonnam(mtmp));
  131.         newsym(mtmp->mx,mtmp->my);
  132.     }
  133.     if (u.usym == S_DEMON) {    /* Won't blackmail their own. */
  134.  
  135.         pline("%s says, \"Good hunting, %s.\" and vanishes.",
  136.           Amonnam(mtmp), flags.female ? "Sister" : "Brother");
  137.         rloc(mtmp);
  138.         return(1);
  139.     }
  140.     demand = (u.ugold * (rnd(80) + 20 * Athome)) /
  141.          100 * (1 + (sgn(u.ualign.type) == sgn(mtmp->data->maligntyp)));
  142.     if (!demand)          /* you have no gold */
  143.         return mtmp->mpeaceful = 0;
  144.     else {
  145.         pline("%s demands %ld zorkmid%s for safe passage.",
  146.           Amonnam(mtmp), demand, plur(demand));
  147.  
  148.         if ((offer = bribe(mtmp)) >= demand) {
  149.         pline("%s vanishes, laughing about cowardly mortals.",
  150.               Amonnam(mtmp));
  151.         } else {
  152.         if ((long)rnd(40) > (demand - offer)) {
  153.             pline("%s scowls at you menacingly, then vanishes.",
  154.               Amonnam(mtmp));
  155.         } else {
  156.             pline("%s gets angry...", Amonnam(mtmp));
  157.             return mtmp->mpeaceful = 0;
  158.         }
  159.         }
  160.     }
  161.     mongone(mtmp);
  162.     return(1);
  163. }
  164.  
  165. long
  166. bribe(mtmp)
  167. struct monst *mtmp;
  168. {
  169.     char buf[80];
  170.     long offer;
  171.  
  172.     getlin("How much will you offer?", buf);
  173.     (void) sscanf(buf, "%ld", &offer);
  174.  
  175.     /*Michael Paddon -- fix for negative offer to monster*/
  176.     /*JAR880815 - */
  177.      if (offer < 0L) {
  178.          You("try to shortchange %s, but fumble.",
  179.              mon_nam(mtmp));
  180.          offer = 0L;
  181.      } else if (offer == 0L) {
  182.         You("refuse.");
  183.      } else if (offer >= u.ugold) {
  184.         You("give %s all your gold.", mon_nam(mtmp));
  185.         offer = u.ugold;
  186.     } else You("give %s %ld zorkmid%s.", mon_nam(mtmp), offer,
  187.            plur(offer));
  188.  
  189.     u.ugold -= offer;
  190.     mtmp->mgold += offer;
  191.     flags.botl = 1;
  192.     return(offer);
  193. }
  194.  
  195. int
  196. dprince(atyp)
  197. aligntyp atyp;
  198. {
  199.     int tryct, pm;
  200.  
  201.     for (tryct = 0; tryct < 20; tryct++) {
  202.         pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS);
  203.         if (!(mons[pm].geno & (G_GENOD | G_EXTINCT)) &&
  204.             (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
  205.         return(pm);
  206.     }
  207.     return(dlord(atyp));    /* approximate */
  208. }
  209.  
  210. int
  211. dlord(atyp)
  212. aligntyp atyp;
  213. {
  214.     int tryct, pm;
  215.  
  216.     for (tryct = 0; tryct < 20; tryct++) {
  217.         pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX);
  218.         if (!(mons[pm].geno & (G_GENOD | G_EXTINCT)) &&
  219.             (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
  220.         return(pm);
  221.     }
  222.     return(ndemon(atyp));    /* approximate */
  223. }
  224.  
  225. /* create lawful (good) lord */
  226. int
  227. llord()
  228. {
  229.     if (!(mons[PM_ARCHON].geno & (G_GENOD | G_EXTINCT)))
  230.         return(PM_ARCHON);
  231.  
  232.     return(lminion());    /* approximate */
  233. }
  234.  
  235. int
  236. lminion()
  237. {
  238.     int    tryct;
  239.     struct    permonst *ptr;
  240.  
  241.     for (tryct = 0; tryct < 20; tryct++) {
  242.         ptr = mkclass(S_ANGEL,0);
  243.         if (ptr && !is_lord(ptr))
  244.         return(monsndx(ptr));
  245.     }
  246.  
  247.     return(0);
  248. }
  249.  
  250. int
  251. ndemon(atyp)
  252. aligntyp atyp;
  253. {
  254.     int    tryct;
  255.     struct    permonst *ptr;
  256.  
  257.     for (tryct = 0; tryct < 20; tryct++) {
  258.         ptr = mkclass(S_DEMON, 0);
  259.         if (is_ndemon(ptr) &&
  260.             (atyp == A_NONE || sgn(ptr->maligntyp) == sgn(atyp)))
  261.         return(monsndx(ptr));
  262.     }
  263.  
  264.     return(0);
  265. }
  266.  
  267. /*minion.c*/
  268.